
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="../../assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="../../assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="../../assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="../../assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="../../assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="../../assets/css/app.css">
    <link rel="stylesheet" href="../../assets/css/amazeui.tree.min.css" />
    <script src="../../assets/js/jquery.min.js"></script>
    <script src="../../assets/js/amazeui.tree.min.js"></script>
    <style>
        .am-tree{
            color: #FFFFFF;
        }
        .am-tree .am-tree-branch-name, .am-tree .am-tree-item .am-tree-item-name:hover {
            color: #FFFFFF;
        }

    </style>
</head>

<body data-type="widgets">
<script src="../../assets/js/theme.js"></script>

<div >
    <div style="width: 17%;float: left;padding: 20px;">
        <!-- 树型菜单 -->
        <ul class="am-tree" id="firstTree">
            <li class="am-tree-branch am-hide" data-template="treebranch">
                <div class="am-tree-branch-header">
                    <button class="am-tree-branch-name">
                        <span class="am-tree-icon am-tree-icon-folder"></span>
                        <span class="am-tree-label"></span>
                    </button>
                </div>
                <ul class="am-tree-branch-children"></ul>
                <div class="am-tree-loader"><span class="am-icon-spin am-icon-spinner"></span></div>
            </li>
            <li class="am-tree-item am-hide" data-template="treeitem" class="treeitem">
                <button class="am-tree-item-name">
                    <span class="am-tree-icon am-tree-icon-item"></span>
                    <span class="am-tree-label"></span>
                </button>
            </li>
        </ul>
    </div>
<!-- 内容区域 -->
    <div style="width: 83%;float: right;padding-right: 0px">
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">药品目录</div>
                </div>
                <div class="widget-body  am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary" id="moreUpdate"><span class="am-icon-save"></span> 批量更新 </button>
                                    <input type="reset" class="am-btn am-btn-default" id="reset" value="重置"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select data-am-selected="{btnSize: 'sm'}">
                                <option value="option1">所有类别</option>
                                <option value="option2">IT业界</option>
                                <option value="option3">数码产品</option>
                                <option value="option3">笔记本电脑</option>
                                <option value="option3">平板电脑</option>
                                <option value="option3">只能手机</option>
                                <option value="option3">超极本</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button"></button>
          </span>
                        </div>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                            <thead>
                            <tr>
                                <th>药品名称</th>
                                <th>进价</th>
                                <th>单位</th>
                                <th>建议售价</th>
                                <th>地方价</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tableData">

                            <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr" id="div-pager">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<div class="am-modal am-modal-no-btn" tabindex="-1" id="win-modal">
    <div class="am-modal-dialog">
        <div class="am-modal-bd">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-body am-fr" style="text-align: left">

                                <form class="am-form tpl-form-border-form tpl-form-border-br">
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">标题 <span class="tpl-form-line-small-title">Title</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="请输入标题文字">
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label  class="am-u-sm-3 am-form-label">发布时间 <span class="tpl-form-line-small-title">Time</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="am-form-field tpl-form-no-bg" placeholder="发布时间" data-am-datepicker="" readonly="">
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label  class="am-u-sm-3 am-form-label">作者 <span class="tpl-form-line-small-title">Author</span></label>
                                        <div class="am-u-sm-9">
                                            <select data-am-selected="{searchBox: 1}" style="display: none;">
                                                <option value="a">-The.CC</option>
                                                <option value="b">夕风色</option>
                                                <option value="o">Orange</option>
                                            </select>

                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">SEO关键字 <span class="tpl-form-line-small-title">SEO</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" placeholder="输入SEO关键字">
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-weibo" class="am-u-sm-3 am-form-label">封面图 <span class="tpl-form-line-small-title">Images</span></label>
                                        <div class="am-u-sm-9">
                                            <div class="am-form-group am-form-file">
                                                <div class="tpl-form-file-img">
                                                    <img src="assets/img/a5.png" alt="">
                                                </div>
                                                <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                                    <i class="am-icon-cloud-upload"></i> 添加封面图片</button>
                                                <input id="doc-form-file" type="file" multiple="">
                                            </div>

                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-weibo" class="am-u-sm-3 am-form-label">添加分类 <span class="tpl-form-line-small-title">Type</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" id="user-weibo" placeholder="请添加分类用点号隔开">
                                            <div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-intro" class="am-u-sm-3 am-form-label">隐藏文章</label>
                                        <div class="am-u-sm-9">
                                            <div class="tpl-switch">
                                                <input type="checkbox" class="ios-switch bigswitch tpl-switch-btn" checked="">
                                                <div class="tpl-switch-btn-view">
                                                    <div>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-intro" class="am-u-sm-3 am-form-label">文章内容</label>
                                        <div class="am-u-sm-9">
                                            <textarea class="" rows="10" id="user-intro" placeholder="请输入文章内容"></textarea>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


        <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">杏林名家</div>
                <div class="am-modal-bd">
                    你，确定要删除这条记录吗？
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="noExists">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">杏林名家</div>
                <div class="am-modal-bd">
                    该地区暂未设置药品信息，是否立即设置
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="theChanged">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">杏林名家</div>
                <div class="am-modal-bd">
                    药品信息已修改，请先批量更新或重置
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="updateOk">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">杏林名家</div>
                <div class="am-modal-bd">
                    药品信息批量更新成功
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="importOk">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">杏林名家</div>
                <div class="am-modal-bd">
                    该区域药品信息设置成功
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        </div>

</div>
<script src="../../assets/js/amazeui.min.js"></script>
<script src="../../assets/js/amazeui.datatables.min.js"></script>
<script src="../../assets/js/dataTables.responsive.min.js"></script>
<script src="../../assets/js/app.js"></script>
<script>
    var $modal ;
    $(document).ready(function(){
        tableData(1);
        $modal = $('#win-modal');
    });

    function tableData(page){
        $.ajax({
            url:"/x/medical/areaMedicalList",
            data:{"page":page},
            success:function(da){
                $("#tableData").html(da);
            }
        })
    }

    function areaTableData(areaId,page){
        $.ajax({
            url:"/area/areaMedicalList",
            data:{"page":page,"areaCode":areaId},
            success:function(da){
                $("#tableData").html(da);
            }
        })
    }

    function addMedical(){
        $modal.modal({
            width:document.documentElement.clientWidth-200
        });
    }

    function deleteData(id){
        $('#my-confirm').modal({
            onConfirm: function(options) {
                alert("确定");
            },
            onCancel: function() {
                alert('算求，不弄了');
            }
        });
    }
    /*function isExists(areaCode){
        $('#noExists').modal({
            onConfirm: function(options) {
                var data = {"areaId":areaCode};
                console.log("id："+areaCode);
                $.ajax({
                    url:"/area/improtTemplateData",
                    type:"post",
                    dataType:"json",
                    data:data,
                    success:function(result){
                        console.log("数据导入成功");
                        areaTableData(areaCode,1);
                        $('#importOk').modal({
                            onConfirm: function(options) {
                                $modal = $('#win-modal');
                            }
                        });
                    },error:function(){
                        console.log("ajax出错");
                    }
                });
            },
            onCancel: function() {
                tableData(1);
            }
            /!*onConfirm: function(options) {
                tableData(1);
                $modal = $('#win-modal');
            }*!/
        });
    }*/

    function theChanged(){
        $('#theChanged').modal({
            onConfirm: function(options) {
                $modal = $('#win-modal');
            }
        });
    }
    var pageNo = 1; // 页码
    var isChanged = false;  // 页面数据更新状态，默认未更新
    $("#tableData").on("change",".medicalPrice",function(){
        isChanged = true;
    });
    $("#tableData").on("change",".remark",function(){
        isChanged = true;
    });

    var priceList = new Array();    // 存储更新前的价格
    var remarkList = new Array();   // 存储更新前的备注
    // 重置
    $("#reset").click(function(){
        $(priceList).each(function(i){
            $(".medicalPrice")[i].value =this;
        })
        $(remarkList).each(function(i){
            $(".remark")[i].value =this;
        })
        // 重置后修改页面数据更新状态为false
        isChanged = false;
    });

    // demo 1
    var data = "";
    $.ajax({
        url:"/area/getAreaList",
        type:"post",
        dataType:"json",
        data:"{'a':'a'}",
        success:function(result){
            console.log("ajax成功");
            console.log(result.data);
            data = result.data;
            $('#firstTree').tree({
                dataSource: function(options, callback) {
                    // 模拟异步加载
                    setTimeout(function() {
                        callback({data: options.products || data});
                    }, 400);
                },
                multiSelect: false,
                cacheItems: true,
                folderSelect: false
            });
        },error:function(){
            console.log("ajax出错");
        }
    });

    $(function(){
        // 点击区域
        /*$("#firstTree").on("click",".am-tree-item",function(){
            alert("a")
        })*/
        var areaId = "";
        $('#firstTree').on('selected.tree.amui', function (event, data) {
            // do something with data: { selected: [array], target: [object] }
            areaId = data.target.codeid;
            console.log(areaId);
            var data = {"areaId":areaId};
            $.ajax({
                url:"/area/isExists",
                type:"post",
                dataType:"json",
                data:data,
                success:function(result){
                    console.log("ajax成功"+result.data.flag+"-----"+result.data.areaId);
                    if(result.data.flag){    // 设置过
                        areaTableData(areaId,1);
                        $modal = $('#win-modal');
                    }else{              // 未设置
                        //
                        tableData(1);
                    }
                },error:function(){
                    console.log("ajax出错");
                }
            });
        });


        // 批量更新
        $("#moreUpdate").click(function(){
            // 验证是否设置过该区域的药品信息
            var data = {"areaId":areaId};
            $.ajax({
                url:"/area/isExists",
                type:"post",
                dataType:"json",
                data:data,
                success:function(result){
                    // 获取页面中的价格与备注列表
                    var priceArr = "";
                    $(".medicalPrice").each(function(i){
                        priceArr+=this.value+",";
                    });
                    var remarkArr ="";
                    $(".remark").each(function(i){
                        remarkArr+=this.value+",";
                    });
                    if(result.data.flag){    // 设置过

                        var uuidArr = "";
                        $(".uuidArr").each(function(i){
                            console.log(this.value);
                            uuidArr+=this.value+",";
                        });
                        console.log(uuidArr)

                        var data = {"areaId":result.data.areaId,"priceArr":priceArr,"remarkArr":remarkArr,"uuidArr":uuidArr};
                        $.ajax({
                            url:"/area/moreUpdate",
                            type:"post",
                            dataType:"json",
                            data:data,
                            success:function(result){
                                console.log("ajax成功"+areaId);
                                isChanged = false;  // 更改更新状态为未更新状态
                                $('#updateOk').modal({
                                    onConfirm: function(options) {
                                        $modal = $('#win-modal');
                                    }
                                });
                            },error:function(){
                                console.log("ajax出错");
                            }
                        });
                    }else{              // 未设置
                        //isExists(result.data.areaId);
                        var medicalUUID = "";
                        $(".medical_uuid").each(function(i){
                           medicalUUID += this.value+",";
                        });
                        console.log("areaId:"+result.data.areaId);
                        console.log("uuid:"+medicalUUID);
                        console.log("price:"+priceArr);
                        console.log("remark:"+remarkArr);

                        var areaCode = result.data.areaId;
                        var data = {"areaId":result.data.areaId,"medicalUUID":medicalUUID,"priceArr":priceArr,"remarkArr":remarkArr};
                       $.ajax({
                            url:"/area/improtTemplateData",
                            type:"post",
                            dataType:"json",
                            data:data,
                            success:function(result){
                                console.log("数据导入成功");
                                areaTableData(areaCode,pageNo);
                                isChanged = false;
                                $('#importOk').modal({
                                    onConfirm: function(options) {
                                        $modal = $('#win-modal');
                                    }
                                });
                            },error:function(){
                                console.log("ajax出错");
                            }
                        });

                    }
                },error:function(){
                    console.log("ajax出错");
                }
            });
        });
    });


</script>
</body>

</html>